package com.sdleyou.treepro.common.context;

import com.sdleyou.treepro.system.security.model.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserContext {

    /**
     * 获取当用户
     *
     * @return
     */
    public static User getUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return null;
        }
        //如果含有买家权限则读取卖家信息并返回
        Object someOne = authentication.getDetails();
        if (someOne != null && someOne instanceof User) {
            return (User) someOne;
        }
        return null;
    }
}